class CPilot( object ) :
	__slot__ = [ '__previous ' , ' __sonar' , '__inverse' , '__culdesac ' ] ;
	def __init__ (self) :
		self.__previous = None
		self.__sonar = { ' right' : 0 , 'down ' : 0, ' left' : 0 , ' up' : 0 }
		self.__inverse = {'right' : 'left', 'down' : 'up', 'left' : 'right', 'up' : 'down'}
		self.__culdesac = False
		self.licznik = 0
		print 'dupa'
	
	def setCulDeSac(self, culdesac):
		self.__culdesac = culdesac == True
	def getCulDeSac(self):
		return self.__culdesac
	def isCrossRoad(self):
		return self.__sonar.values().count(True)>2
	
	def setSonar(self, data):
		self.__sonar = data		

	def nextMove(self):
		if self.__sonar.values().count(True)<=1:
			self.setCulDeSac(True)
			for a in self.__sonar.keys():
				if self.__sonar[a] == 1:
					return self.moveTo(a)
		for a in self.__sonar.keys():
			if self.__sonar[a] == 1 and (a!=self.__inverse[self.__previous] or self.__sonar.values().count(True)==1):
				return self.moveTo(a)
		for a in self.__sonar.keys():
			if self.__sonar[a] == 1 and a==self.__previous:
				return self.__previous
	
	def moveTo( self, action) :
		if not self.__inverse.has_key( action) :
			raise ValueError ( 'Unknown robot action ' )
		if self.__sonar[ action ] > 0:
			self.__previous = action
			return action
		else:
			raise ValueError ( 'Imposible motion ')